import  unittest
import time

from playwright.sync_api import sync_playwright


class Playwright(unittest.TestCase):
    def setUp(self):
        self.playwright=sync_playwright().start()
        self.brower=self.playwright.chromium.launch(headless=False)
        self.context=self.brower.new_context()
        self.page=self.context.new_page()

    def tearDown(self):
        self.brower.close()
        self.playwright.stop()
    def test_01(self):
        self.page.goto('http://10.59.9.12:7001/')
        self.page.click('xpath=/html/body/div[1]/div/div[2]/ul/li[1]/a')
        # 断言会员登录
        dy1 = self.page.locator('xpath=/html/body/div[4]/div/div[1]/div[1]/span[1]').text_content()
        assert '会员登录' == dy1
        print('断言1：会员登录', dy1)
        # 输入账号密码
        self.page.fill('input[name=username]', '15235688537')
        self.page.fill('input[name=password]', 'a123123')
        # 强制等待
        time.sleep(15)
        # 点击登录按钮
        self.page.click('a[class="finish-btn"]')

        dy2 = self.page.locator('xpath=/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[1]').text_content()
        assert '您好，15235688537 欢迎回来！' in dy2
        print(dy2)
        time.sleep(2)
        dy2a = self.page.locator('xpath=/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[4]/span').text_content()
        dy21a = dy2a.split()[1]
        print('断言余额:', dy21a)
